package com.winchain.chainbill.tbill.biz.controller;

import com.shell.bee.base.annotation.Logging;
import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.entity.mvc.RetMsg;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.framework.utils.CommonFileUtil;
import com.winchain.chainbill.tbill.biz.BatchTBillStats;
import com.winchain.chainbill.tbill.biz.service.TBillPayConfirmService;
import com.winchain.chainbill.tbill.biz.vo.TbRecVo;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TBillPayConfirmController {
	@Autowired
	private TBillPayConfirmService tBillPayConfirmService;

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "������������������")
	public List<TbRecVo> queryPayConfirmList(PageLimit limit, String cusName, String billCode) {
		return this.tBillPayConfirmService.queryPayConfirmList(limit, cusName, billCode);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "��������")
	public RetMsg confirm(String dctIds, String pmtDate, BigDecimal recvAmt, BigDecimal dctInt, Integer dctDays)
			throws IOException {
		if (StringUtil.emptyAndNull(dctIds)) {
			return new RetMsg("error", true, "����������");
		}
		String[] dctIdArr = dctIds.split(",");
		BatchTBillStats stats = this.tBillPayConfirmService.confirm(dctIdArr, pmtDate, recvAmt, dctInt, dctDays);
		if (dctIdArr.length == stats.getAffectedRows()) {
			return new RetMsg("success", false, "������������");
		}
		if (stats.getAffectedRows() == 0) {
			return new RetMsg("error", false, "������������", CommonFileUtil.changMsg(stats.getAbnormalMsg()));
		}
		return new RetMsg("warning", false, "����������������", CommonFileUtil.changMsg(stats.getAbnormalMsg()));
	}
}
